﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="pgAdmAC.aspx.cs" Inherits="EGuayas.Web.Auditoria.Admin.Cumplimiento.pgAdmAC" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="~/Resources/css/Style.css" rel="stylesheet" />
    <!-- Load Ext JS -->
    <script src="../../../Resources/js/Global.js"></script>
</head>
<body>
    <form runat="server">

    <ext:ResourceManager runat="server"></ext:ResourceManager>
    <ext:Viewport ID="Viewport1" runat="server" Layout="BorderLayout">
        <Items>
            <%-- Hidden almacena IdPageSession  --%>
            <ext:Hidden Text="" ID="hddIdSelect" runat="server" ></ext:Hidden>
            <ext:Panel ID="Panel1" runat="server" Region="North" BodyPadding="6"
                TitleCollapse="false" ButtonAlign="Center" Border="false">
                <Items>
                    <ext:Panel ID="panC1" runat="server" Layout="ColumnLayout" Border="false">
                        <Items>
                            <ext:Panel ID="panC1Col1" runat="server" ColumnWidth=".33" Border="false">
                                <Items>
                                    <ext:ComboBox Editable="false" ID="cbbProvincia" runat="server" FieldLabel="Provincia" ValueField="Id" DisplayField="Nombre">
                                        <Store>
                                            <ext:Store runat="server" ID="stoProvincia">
                                                <Model>
                                                    <ext:Model runat="server" IDProperty="Id">
                                                        <Fields>
                                                            <ext:ModelField Name="Id"></ext:ModelField>
                                                            <ext:ModelField Name="Nombre"></ext:ModelField>
                                                        </Fields>
                                                    </ext:Model>
                                                </Model>
                                            </ext:Store>
                                        </Store>
                                        <Triggers>
                                            <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                        </Triggers>
                                        <Listeners>
                                            <Select Handler="this.getTrigger(0).show();" />
                                            <BeforeQuery Handler="this.getTrigger(0)[this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                            <TriggerClick Handler="if (index == 0) { 
                                           this.clearValue(); 
                                           this.getTrigger(0).hide();
                                       }" />
                                        </Listeners>
                                        <DirectEvents>
                                            <Select OnEvent="cbbProvincia_Select">
                                                <ExtraParams>
                                                    <ext:Parameter Name="Id" Value="#{cbbProvincia}.getValue()" Mode="Raw"/>
                                                </ExtraParams>
                                                <EventMask ShowMask="True"></EventMask>
                                            </Select>
                                        </DirectEvents>
                                    </ext:ComboBox>
                                    <ext:TextField ID="txtCodigo" runat="server" FieldLabel="Código"></ext:TextField>
                                </Items>
                            </ext:Panel>
                            <ext:Panel ID="panC1Col2" runat="server" ColumnWidth=".33" Border="false">
                                <Items>
                                    <ext:ComboBox Editable="false" ID="cbbCanton" runat="server" FieldLabel="Cantón" ValueField="Id" DisplayField="Nombre">
                                        <Store>
                                            <ext:Store runat="server" ID="stoCanton">
                                                <Model>
                                                    <ext:Model ID="Model3" runat="server" IDProperty="Id">
                                                        <Fields>
                                                            <ext:ModelField Name="Id"></ext:ModelField>
                                                            <ext:ModelField Name="Nombre"></ext:ModelField>
                                                        </Fields>
                                                    </ext:Model>
                                                </Model>
                                            </ext:Store>
                                        </Store>
                                        <Triggers>
                                            <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                        </Triggers>
                                        <Listeners>
                                            <Select Handler="this.getTrigger(0).show();" />
                                            <BeforeQuery Handler="this.getTrigger(0)[this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                            <TriggerClick Handler="if (index == 0) { 
                                           this.clearValue(); 
                                           this.getTrigger(0).hide();
                                       }" />
                                        </Listeners>
                                        <DirectEvents>
                                            <Select OnEvent="cbbCanton_Select">
                                                <ExtraParams>
                                                    <ext:Parameter Name="Id" Value="#{cbbCanton}.getValue()" Mode="Raw"/>
                                                </ExtraParams>
                                                <EventMask ShowMask="True"></EventMask>
                                            </Select>
                                        </DirectEvents>
                                    </ext:ComboBox>
                                    <ext:TextField ID="txtNombre" runat="server" FieldLabel="Nombre"></ext:TextField>
                                </Items>
                            </ext:Panel>
                            <ext:Panel ID="panC1Col3" runat="server" ColumnWidth=".33" Border="false">
                                <Items>
                                    <ext:ComboBox Editable="false" ID="cbbParroquia" runat="server" FieldLabel="Parroquia" ValueField="Id" DisplayField="Nombre">
                                        <Store>
                                            <ext:Store runat="server" ID="stoParroquia">
                                                <Model>
                                                    <ext:Model ID="Model4" runat="server" IDProperty="Id">
                                                        <Fields>
                                                            <ext:ModelField Name="Id"></ext:ModelField>
                                                            <ext:ModelField Name="Nombre"></ext:ModelField>
                                                        </Fields>
                                                    </ext:Model>
                                                </Model>
                                            </ext:Store>
                                        </Store>
                                        <Triggers>
                                            <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                        </Triggers>
                                        <Listeners>
                                            <Select Handler="this.getTrigger(0).show();" />
                                            <BeforeQuery Handler="this.getTrigger(0)[this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                            <TriggerClick Handler="if (index == 0) { 
                                           this.clearValue(); 
                                           this.getTrigger(0).hide();
                                       }" />
                                        </Listeners>
                                    </ext:ComboBox>
                                </Items>
                            </ext:Panel>
                        </Items>
                    </ext:Panel>
                </Items>
                <Buttons>
                    <ext:Button ID="btnBuscar" runat="server" Text="Buscar">
                        <DirectEvents>
                            <Click OnEvent="btnBuscar_Click">
                                <ExtraParams>
                                    <ext:Parameter Name="Codigo" Value="#{txtCodigo}.getValue()" Mode="Raw"/>
                                    <ext:Parameter Name="Nombre" Value="#{txtNombre}.getValue()" Mode="Raw"/>
                                    <ext:Parameter Name="ProvinciaId" Value="#{cbbProvincia}.getValue()==null?'':#{cbbProvincia}.getValue()" Mode="Raw"/>
                                    <ext:Parameter Name="CantonId" Value="#{cbbCanton}.getValue()==null?'':#{cbbCanton}.getValue()" Mode="Raw"/>
                                    <ext:Parameter Name="ParroquiaId" Value="#{cbbParroquia}.getValue()==null?'':#{cbbParroquia}.getValue()" Mode="Raw"/>
                                </ExtraParams>
                                <EventMask ShowMask="True"></EventMask>
                            </Click>
                        </DirectEvents>
                    </ext:Button>
                </Buttons>
            </ext:Panel>
            <ext:GridPanel runat="server" ID="gpnAuditoria" Title="Expedientes de Licencias para control y seguimiento"
                Region="Center">
                <Store>
                    <ext:Store runat="server" ID="stoExpedienteAud">
                        <Model>
                            <ext:Model ID="Model2" runat="server" IDProperty="Id">
                                <Fields>
                                    <ext:ModelField Name="Id" />
                                    <ext:ModelField Name="ExpedienteId" />
                                    <ext:ModelField Name="Nombre" />
                                    <ext:ModelField Name="Regulado" />
                                    <ext:ModelField Name="Descripcion" />
                                    <ext:ModelField Name="Estado" />
                                    <ext:ModelField Name="EstadoFase" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
                <ColumnModel>
                    <Columns>
                        <ext:Column runat="server" Text="Nombre" Flex="1" DataIndex="Nombre" />
                        <ext:Column runat="server" Text="Regulado" DataIndex="Regulado" Width="120" />
                        <ext:Column runat="server" Text="Descripción" DataIndex="Descripcion" Width="150" />                      
                        <ext:Column  runat="server" Text="Estado" Width="80" DataIndex="EstadoFase">
                          <%--   <Renderer Fn="pgFnAdmin.FormatEstado" />--%>
                        </ext:Column>
                        <ext:Column ID="Column13" runat="server"  Width="70" Align="Right" RightCommandAlign="false"  >
                                        <Commands>
                                            <ext:ImageCommand CommandName="CmdDocAsoc" Icon="PageWhiteCopy"  ToolTip-Text="Ver documentos de expedientes"/>                                                           
                                        </Commands>
                                             <%-- <PrepareCommand Fn="pgFnAdmin.PrepareDocAsociados" />--%>
                                        <Listeners> 
                                                <Command Handler="AppGlobalJs.mostrarVentanaUrl('../../../Auditoria/admin/pgDocGlobalAuditoria.aspx?Id='+record.data.ExpedienteId,record.data.Nombre);" />                                                         
                                        </Listeners>
                      </ext:Column> 
                    </Columns>
                </ColumnModel>
                <DirectEvents>
                    <Select OnEvent="gpnAuditoria_Select" Before="App.hddIdSelect.setValue(record.data.Id);">
                        <EventMask ShowMask="True"></EventMask>
                        <ExtraParams>
                            <ext:Parameter Name="Id" Value="record.data.Id" Mode="Raw" />
                        </ExtraParams>
                    </Select>
                </DirectEvents>
              
            </ext:GridPanel>
            <ext:GridPanel runat="server" ID="gpnAuditoriaCumplimiento" Region="South" Height="130">
                <TopBar>
                    <ext:Toolbar ID="Toolbar1" runat="server">
                        <Items>
                            <ext:Label ID="Label1" runat="server" Text="Listado de Auditorias de Cumplimiento"></ext:Label>
                            <ext:ToolbarFill ID="ToolbarFill1" runat="server" />
                            <ext:Button ID="btnNuevaAC" runat="server" Text="Nueva" Icon="ApplicationFormAdd">
                                <Listeners>
                                    <Click Handler="pgFnAdmin.ShowNuevoExpediente();"></Click>
                                </Listeners>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <Store>
                    <ext:Store runat="server" ID="stoAC">
                        <Model>
                            <ext:Model ID="Model1" runat="server" IDProperty="Id">
                                <Fields>
                                    <ext:ModelField Name="Id" />
                                    <ext:ModelField Name="ExpedienteId" />
                                    <ext:ModelField Name="ExpedienteAuditoriaId" />
                                    <ext:ModelField Name="Nombre" />
                                    <ext:ModelField Name="Regulado" />
                                    <ext:ModelField Name="Descripcion" />
                                    <ext:ModelField Name="Estado" />
                                    <ext:ModelField Name="EstadoFase" />
                                    <ext:ModelField Name="Promotor" />
                                    <ext:ModelField Name="FechaInicio"  Type="Date"/>
                                    <ext:ModelField Name="FechaFin" Type="Date"/>
                                    <ext:ModelField Name="Alias" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
                <ColumnModel>
                    <Columns>
                        <ext:Column ID="Column1"  runat="server" Text="Auditoria" Flex="1" DataIndex="Nombre" />
                        <ext:Column ID="Column2"  runat="server" Text="Nombre" Flex="1" DataIndex="Alias" />
                       
                        <ext:Column runat="server" Text="Promotor" DataIndex="Promotor" Width="120" />
                        <ext:Column runat="server" Text="Descripción" DataIndex="Descripcion" Width="150" />
                        <ext:Column   runat="server" Text="Estado" Width="80" DataIndex="EstadoFase">
                            <%--
                            <Renderer Fn="pgFnAdmin.FormatEstado" />
                             --%>
                        </ext:Column>
                        <ext:DateColumn runat="server"  Text="Fecha Inicio"    DataIndex ="FechaInicio"   />
                        <ext:DateColumn runat="server"  Text="Fecha Fin"       DataIndex ="FechaFin"   />
                        <ext:CommandColumn ID="CommandColumn1"  runat="server" Width="80" Text="Editar" >
	                        <Commands>
	                        <ext:GridCommand Icon="ApplicationFormEdit" CommandName="EditarProceso">
		                        <ToolTip Text="Editar Monitoreo" />
	                        </ext:GridCommand>
	                      
                        </Commands>
	                        <Listeners>
		                        <Command Handler="pgFnAdmin.UpdateNuevoExpediente(record);"></Command>
	                        </Listeners>
                        </ext:CommandColumn> 
                        
                        <ext:CommandColumn  runat="server" Width="80">
                            <Commands>
                                <ext:GridCommand Icon="TableGo" CommandName="VerProceso">
                                    <ToolTip Text="Ver proceso de licenciamiento" />
                                </ext:GridCommand>
                                <ext:CommandSeparator />
                            </Commands>
                            <%--<DirectEvents>
                                <Command OnEvent="VerProceso_Comand" Success="pgFnAdmin.LinkExpediente(record);">
                                    <ExtraParams>
                                        <ext:Parameter Name="Id" Value="record.data.Id" Mode="Raw"/>
                                        <ext:Parameter Name="ExpedienteId" Value="record.data.ExpedienteId" Mode="Raw"/>
                                    </ExtraParams>
                                </Command>
                            </DirectEvents>--%>
                            <Listeners>
                                <Command Handler="pgFnAdmin.LinkExpediente(record);"></Command>
                            </Listeners>
                        </ext:CommandColumn>

                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
        </Items>
    </ext:Viewport>
      <ext:XScript ID="XScript1" runat="server">
        <script type="text/javascript">
            var pgFnAdmin = new Object();
            pgFnAdmin.winUrl = null;
            pgFnAdmin.FormatEstado = function (value) {
                var template = '<span>{0}</span>';
                return Ext.String.format(template, (value =="N") ? "No" : "Si", value);

            };
            //Cerrar ventana creada
            pgFnAdmin.BeforeClose = function (win,namewin) {
                try{
                    Ext.Msg.confirm('Aviso', 'Desea cerrar ventana <b> auditoria de cumplimiento de '+namewin+'</b>?', function (btn) {
                        if (btn == 'yes') 
                        { 
                            win.forceHide();
                            return true;
                        }
                    });
                    return false;
                } catch (jsbug) {
                    AppGlobalJs.showBug("pgFnAdmin.BeforeClose :" + jsbug)
                }
            };
            //Cerrar ventana creada
            pgFnAdmin.ClosePgAdmGlobal = function () {
                try 
                {  
                   
                        App.direct.DataBindAuditoriaCumplientoLista(#{hddIdSelect}.getValue(),{
                            success: function (result) {
                      
                            },
                            eventMask: {
                                showMask: true,
                                minDelay: 500
                            }
                        }); 
                  } catch (jsbug) {
                    AppGlobalJs.showBug(" pgFnAdmin.ClosePgAdmGlobal :" + jsbug)
                }
            };
            //Cerrar ventana desde botones de ventanas derivadas
            App.CloseNuevoExpediente =  function () {
                try 
                {
                    if ( pgFnAdmin.winUrl  !=null)
                    {
                        pgFnAdmin.winUrl.close();
                        pgFnAdmin.winUrl=null;
                    }
                } catch (jsbug) {
                    AppGlobalJs.showBug("App.CloseNuevoExpediente :" + jsbug)
                }
                      
            };
            pgFnAdmin.ShowNuevoExpediente = function () {
                var objSelect = App.gpnAuditoria.getRowsValues({ selectedOnly: true });
                if (objSelect.length != 0) {
                    var rowSelect = objSelect[0];
                    pgFnAdmin.winUrl = AppGlobalJs.mostrarVentanaUrl('pgNuevoExpediente.aspx?evt=NUEVO&exp_id=' + rowSelect.ExpedienteId + '&exa_id=' + rowSelect.Id, 'Nueva Auditoria de Cumplimiento de  '+rowSelect.Nombre);
                    pgFnAdmin.winUrl.addListener('close', function (el) { pgFnAdmin.ClosePgAdmGlobal(); el.destroy(); });
                }

            };
            pgFnAdmin.UpdateNuevoExpediente = function (record) {
                pgFnAdmin.winUrl =AppGlobalJs.mostrarVentanaUrl('pgNuevoExpediente.aspx?evt=MODIFICAR&pma_id='+record.data.Id+'&exp_id='+record.data.ExpedienteId,'Modificar Auditoria de Cumplimiento de  '+record.data.Nombre,'#ApplicationFormAdd');                            
                pgFnAdmin.winUrl.addListener('close', function (el) { pgFnAdmin.ClosePgAdmGlobal(); el.destroy(); });       
            };
            pgFnAdmin.LinkExpediente = function (record) {
                pgFnAdmin.winUrl = AppGlobalJs.mostrarVentanaUrl('pgContentCump.aspx?acu_id='+record.data.Id+'&exp_id='+record.data.ExpedienteId+'&exa_id='+record.data.ExpedienteAuditoriaId,'Auditoria de Cumplimiento de '+record.data.Nombre);
                pgFnAdmin.winUrl.addListener('close', function (el) { pgFnAdmin.ClosePgAdmGlobal(); el.destroy(); });    
                pgFnAdmin.winUrl.addListener('beforehide', function (el) { return pgFnAdmin.BeforeClose(el,record.data.Nombre);});            
            };
            /*
            //
             pgFnAdmin.PrepareDocAsociados = function (grid, command, record, row) {
                try
                {
                    if (command.command == 'CmdDocAsoc')
                    {
                      
                        var rolCode=#{hdRol}.getValue();
                        if (rolCode != 'PROMOTOR') {
                           
                            command.hidden = false;
                            command.hideMode = 'visibility';
                        }
                        else
                        {
                            command.hidden = true;
                            command.hideMode = 'display';
                        }


                    }

                } catch (jsbug) {
                    AppGlobalJs.showBug("pgFnAdmin.PrepareDocAsociados : " + jsbug);
                }
            };
            */
        </script>
    </ext:XScript>
        
    </form>
</body>
</html>
